<?php

class Crud_Form_Element_Column_File extends Crud_Form_Element_Column
{
	/**
	 * Create element.
	 * 
	 * @return void
	 */
	public function init()
	{
		$element = $this->getElement();
		$element->setRequired(false);
		
		$column = $this->getColumn();
		
		$config = Config::getInstance()->file_transfer;
		
		$adapter = new File_Transfer_HttpWithDb($column);
		$adapter->setDestination(Config::getInstance()->file_transfer->destination);
		if ($options = Config::getInstance()->file_transfer->options) {
			$adapter->setOptions($options->toArray());
		}
		
		$element->setTransferAdapter($adapter);
		
		$element->addValidator(new Zend_Validate_File_Extension('jpg,png,gif,jpeg'));
		$element->addValidator(new Zend_Validate_File_Count(1));
		$element->addValidator(new Zend_Validate_File_Size(102400));
		//$element->setAttrib('class', 'crud_file');*/
	}
	
	/**
	 * Return element class.
	 * 
	 * @return string
	 */
	protected function _getElementClass()
	{
		return 'Zend_Form_Element_File';
	}
}